
package com.zjff.myshop.front.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.zjff.myshop.front.pojo.vo.HomeCarouselVO;
import com.zjff.myshop.front.pojo.vo.HomeGoodsVO;
import com.zjff.myshop.front.service.HomeService;
import com.zjff.myshop.mapper.HomeMapper;
import com.zjff.myshop.util.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service
public class HomeServiceImpl implements HomeService {

    @Resource
    private HomeMapper homeMapper;

    @Override
    public List<HomeGoodsVO> selectGoodsVOList(HashMap map) {
        List<HomeGoodsVO> homeGoodsVOList = new ArrayList<>();
        List<HashMap<String, Object>> mapList = homeMapper.selectGoodsVOList(map);

        //Map数组转Bean数组
        for (HashMap<String, Object> one : mapList) {
            HomeGoodsVO vo = BeanUtils.mapToBean(one, HomeGoodsVO.class);
            if (ObjectUtil.isNotNull(vo)) {
                homeGoodsVOList.add(vo);
            }
        }
        return homeGoodsVOList;
    }

    @Override
    public List<HomeCarouselVO> selectCarouselVOList(HashMap map) {
        List<HomeCarouselVO> carouselVoList = new ArrayList<>();
        List<HashMap<String, Object>> mapList = homeMapper.selectCarouselVOList(map);

        //Map数组转Bean数组
        for (HashMap<String, Object> one : mapList) {
            HomeCarouselVO vo = BeanUtils.mapToBean(one, HomeCarouselVO.class);
            if (ObjectUtil.isNotNull(vo)) {
                carouselVoList.add(vo);
            }
        }
        return carouselVoList;
    }
}
